import Observer from './Observe.js'
//plugin
class Vue {
    constructor(options) {
        this.$el = options.el
        this.$data = options.data || {}
        this.$options = options

        //拦截data对象属性
        new Observer(this.$data)

        this.proxyData()
    }
    /**
     * 使用Vue实例访问时，通过代理拦截，使其操作 this.$data
     */
    proxyData() {
        for (const [key, value] of Object.entries(this.$data)) {
            Object.defineProperty(this, key, {
                get() {
                    return this.$data[key]
                },
                set(newValue) {
                    this.$data[key] = newValue
                },
            })
        }
    }
}

export default Vue
